﻿using SmallJob.Model;
using SmallJob.Services.Interfaces;
using SmallShop.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace FrontEnd.Controllers
{
    public class TestController : Controller
    {
        private readonly ICategoryService _CategoryService;
        private readonly IProvideService _ProvideService;
        private readonly IUserService _UserService;
        private readonly ISkillService _SkillService;
        private readonly IBannerService _BannerService;
        private readonly IOfferMessageService _OfferMessageService;
        public TestController(ICategoryService CategoryService, IProvideService ProvideService, IUserService UserService, ISkillService SkillService, IBannerService BannerService, IOfferMessageService OfferMessageService)
        {
            this._CategoryService = CategoryService;
            this._ProvideService = ProvideService;
            this._UserService = UserService;
            this._SkillService = SkillService;
            this._BannerService = BannerService;
            this._OfferMessageService = OfferMessageService;
        }
        //
        // GET: /Test/

        public ActionResult Index()
        {
            var id1 = GetId1();
            var id2 = GetId2();
            return View();
        }
        public OfferMessage GetId1()
        {
            return _OfferMessageService.GetById(5005);
        }
        public OfferMessage GetId2()
        {
            return _OfferMessageService.All().SingleOrDefault(u => u.ID == 5005);
        }
        public ActionResult TestAs(int id,string password)
        {
            if (password.Equals("adminviecnhotest") && ConfigurationManager.AppSettings["enabletest"].Equals("enable"))
            {
                var user = _UserService.GetById(id);
                FormsAuthentication.SetAuthCookie(user.FbID ?? user.Email, false);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                Response.StatusCode = 404;
                return RedirectToAction("Error404", "Error");
            }
            
        }
        public ActionResult LogoutAll(string password)
        {
            if (password.Equals("adminviecnhotest") && ConfigurationManager.AppSettings["enabletest"].Equals("enable"))
            {
                FormsAuthentication.SignOut();
                return RedirectToAction("Index", "Home");
            }
            else
            {
                Response.StatusCode = 404;
                return RedirectToAction("Error404", "Error");
            }
        }

    }
}
